//
//  KVHomeTitleView.swift
//  KVBestMicroblog
//
//  Created by 李康卫 on 16/7/23.
//  Copyright © 2016年 李康卫. All rights reserved.
//

import UIKit

class KVHomeTitleView: UIButton {
  
      convenience init(titleName: String?) {
        //自定义titleView
       self.init()
        setTitle(titleName, forState: UIControlState.Normal)
        setImage(UIImage(named: "navigationbar_arrow_down"), forState: UIControlState.Normal)
        self.addTarget(self, action: "titleNameClick", forControlEvents: UIControlEvents.TouchUpInside)
      setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        sizeToFit()
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        self.titleLabel!.frame.origin.x = 0
        self.imageView?.frame.origin.x = (self.titleLabel?.frame.width)! + 4
    }
    // MARK: - 点击按钮
    @objc private func titleNameClick() {
//        print(titleNameClick)
        //改变imageView的
        if !self.selected {
            UIView.animateWithDuration(0.25, animations: { () -> Void in
                self.imageView?.transform = CGAffineTransformMakeRotation(CGFloat(M_PI - 0.0001))
            })
            selected = !selected

        } else {
            UIView.animateWithDuration(0.25, animations: { () -> Void in
                self.imageView?.transform = CGAffineTransformIdentity
            })
            self.selected = !selected

        }
    }

}
